package com.springboot.demo.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

import com.springboot.demo.constant.CommonConstant;

/**
 * socket客户端
 *
 * @author supu
 * @since 2020-11-13 10:35
 **/
public class SocketClient {
    public static void main(String[] args) {
        try {
            Socket client = new Socket(CommonConstant.LOCALHOST, CommonConstant.LOCAL_PORT);

            client.setSendBufferSize(100);
            client.setTcpNoDelay(true);

            OutputStream out = client.getOutputStream();

            InputStream in = System.in;

            BufferedReader reader = new BufferedReader(new InputStreamReader(in));

            while (true){
                String line =reader.readLine();
                if(line != null){
                    byte[] bytes = line.getBytes();
                    out.write(bytes);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
